<template>
  <div id="app">
    <el-container style="height: 100vh">
      <el-aside :width="asideWidth" class="aside" :style="{ width: asideWidth }">
        <!-- 侧边栏内容 -->
        <div class="avatar_box">
          <img :src="logoSrc" alt="logo" class="avatar" />
          <span v-show="!isCollapse" class="system_name">海报设计系统</span>
        </div>
        <el-menu
          :default-active="activeMenu"
          class="el-menu-vertical-demo"
          @select="handleMenuSelect"
          :collapse="isCollapse"
        >
          <el-menu-item index="home">
            <router-link :to="{ name: 'home' }">
              <i class="el-icon-menu"></i>
              <span slot="title">首页</span>
            </router-link>
          </el-menu-item>
          <el-submenu index="system">
            <template slot="title">
              <i class="el-icon-setting"></i>
              <span>系统管理</span>
            </template>
            <el-menu-item index="user">
              <router-link :to="{ name: 'user' }">用户管理</router-link>
            </el-menu-item>
            <el-menu-item index="menu">
              <router-link :to="{ name: 'menu' }">菜单管理</router-link>
            </el-menu-item>
            <el-menu-item index="role">
              <router-link :to="{ name: 'role' }">角色管理</router-link>
            </el-menu-item>
          </el-submenu>
          <el-menu-item index="poster">
            <router-link :to="{ name: 'poster' }">
              <i class="el-icon-picture"></i>
              <span slot="title">海报管理</span>
            </router-link>
          </el-menu-item>
          <el-menu-item index="material">
            <router-link :to="{ name: 'material' }">
              <i class="el-icon-document"></i>
              <span slot="title">素材管理</span>
            </router-link>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header class="header">
          <div class="header-left">
            <i
              :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
              @click="toggleAside"
            ></i>
            <el-breadcrumb
              class="breadcrumb"
              separator-class="el-icon-arrow-right"
            >
              <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item
                v-for="(item, index) in breadcrumbItems"
                :key="index"
                :to="item.to"
                @click.native.prevent="handleBreadcrumbClick(item.name)"
              >
                {{ item.label }}
              </el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <div class="header-right">
            <el-avatar :src="avatarSrc" size="medium"></el-avatar>
            <el-dropdown>
              <span class="el-dropdown-link">
                admin<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>个人中心</el-dropdown-item>
                <el-dropdown-item>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <el-main class="main">
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      logoSrc: require('../assets/logo.jpg'),
      avatarSrc: require('../assets/tx.jpg'),
      breadcrumbItems: [],
      isCollapse: false,
      asideWidth: '200px',
      activeMenu: 'home',
    };
  },
  methods: {
    handleMenuSelect(index) {
      this.activeMenu = index;
      this.updateBreadcrumb(index);
    },
    toggleAside() {
      this.isCollapse = !this.isCollapse;
      this.asideWidth = this.isCollapse ? '64px' : '200px';
    },
    handleBreadcrumbClick(name) {
      this.activeMenu = name;
      this.updateBreadcrumb(name);
    },
    updateBreadcrumb(name) {
      const breadcrumbMap = {
        home: [],
        user: [
          { label: '系统管理', name: 'system' },
          { label: '用户管理', name: 'user' },
        ],
        menu: [
          { label: '系统管理', name: 'system' },
          { label: '菜单管理', name: 'menu' },
        ],
        role: [
          { label: '系统管理', name: 'system' },
          { label: '角色管理', name: 'role' },
        ],
        poster: [{ label: '海报管理', name: 'poster' }],
        material: [{ label: '素材管理', name: 'material' }],
      };

      this.breadcrumbItems = breadcrumbMap[name] || [];
    },
  },
};
</script>

<style scoped>
html,
body,
#app {
  height: 100%;
  margin: 0;
}

.el-container {
  height: 100%;
}

.el-aside {
  background-color: #333;
  color: #fff;
  height: 100%;
}

.avatar_box {
  display: flex;
  align-items: center;
  padding-left: 12px;
  background-color: #333; /* 设置为深色 */
  height: 60px;
  border-bottom: 1px solid #555;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}

.system_name {
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  transition: opacity 0.3s; /* 添加过渡效果 */
}

.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
}

.header-right .el-avatar {
  margin-right: 10px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  flex-grow: 1;
  padding-top: 0;
}

.breadcrumb {
  margin-left: 20px;
  color: #333;
  font-size: 14px;
}

::v-deep .el-icon-arrow-right:before {
  color: black;
}

.breadcrumb .el-breadcrumb__inner {
  font-size: 14px;
}

.el-menu-vertical-demo {
  background-color: #333; /* 设置为深色 */
  border-right: none;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

::v-deep .el-menu-item,
::v-deep .el-submenu__title {
  background-color: #333; /* 设置为深色 */
  color: #fff;
}

::v-deep .el-menu-item:hover,
::v-deep .el-submenu__title:hover,
::v-deep .el-menu-item.is-active {
  background-color: #444 !important;
}

::v-deep .el-submenu__icon-arrow {
  display: none;
}
</style>
